﻿//tab菜单
function tabMenu() {
	$("li[class='ui-state-default ui-corner-top ui-tabs-selected ui-state-active']").contextMenu("tabMenu", {
	     onContextMenu: function(e) {
             var a =e.currentTarget.className;
             if (a=="ui-state-default ui-corner-top ui-state-hover ui-state-focus") {  
                  return false; 
             }else {
                  return true;
             }
         },
	     bindings:{
	          "closeother":function (t) {
		          var selected = $tabs.tabs('option', 'selected');
		              var size =tab_counter;
		              for(var i=size-1;i<size&&i>0;i--){
		                  if(i==selected){continue;}
		                  $tabs.tabs("remove", i);
		                  tab_counter--;
		              }
	          }, 
	          "closeall":function (e) {
	              var selected = $tabs.tabs('option', 'selected');
	              var size =tab_counter;
	                  for(var i=size-1;i<size&&i>0;i--){
		                  $tabs.tabs("remove", i);
		                  tab_counter--;
		              }
	          }
	    }
	});
}

//监听tab单项关闭
$("#centerDiv span.ui-icon-close").live("click", function () {
	var index = $("li", $tabs).index($(this).parent());
	$tabs.tabs("remove", index);
	tab_counter--;
});

//关闭tab项
function colseTab() {
    var selected = $tabs.tabs('option', 'selected');
    $tabs.tabs("remove", selected);
    tab_counter--;
}

//添加tab项
function openTab(id,title,url) {
	if (typeof(url) == "undefined"){
	    return;
	}
    var tabid ="#tab_" +id;
	if($("#tab_"+id).html() != null ) {
		 $tabs.tabs('select',tabid);
		 $("#tab_" +id,"#centerDiv").load(url);
    }else{
		 $tabs.tabs("add", tabid, title);
		 $("#tab_" +id).attr("url",url);
	     $("#tab_" +id,"#centerDiv").load(url);
	     tab_counter++;
    }
	tabMenu();
    //divBlockUIOpen('centerDiv','正在加载页面数据...',false,0);
}
